-
Notifications
You must be signed in to change notification settings - Fork 1
8-hadongun #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8-hadongun #29
Conversation
dohyeondol1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ°λ¨ν 그리λ λ¬Έμ λ€μ!
νμ΄ ν° μμΌλ‘ μ λ ¬ν΄μ μ΅λκ°μ λμΆν΄λμ΅λλ€.
C++ μ½λ
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> tip(N);
for(int& t : tip)
cin >> t;
sort(tip.rbegin(), tip.rend());
long long totalTip = 0;
for(int i = 0; i < N; i++) {
if(tip[i]-i < 0) continue;
totalTip += tip[i]-i;
}
cout << totalTip << '\n';
return 0;
}μνκ³΅λΆ νμ΄ν ~
|
μ λ νμ΄μ¬3
import sys
input = sys.stdin.readline
N = int(input())
tips=[]
for _ in range(N):
tips.append(int(input()))
tips.sort(reverse=True)
total_tip = 0
for i in range(N):
actual_tip = tips[i] - i
if actual_tip > 0:
total_tip += actual_tip
print(total_tip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄λ²μ λ°°μ΄ μ½μ
μ λ ¬μ μ΄μ©ν΄μ νμ΄λ΄€μ΅λλ€! λ°±μ€μμ μκ°μ΄κ³Όκ° λ¨λ€μ.
λ°°μ΄λλ‘ μκ°λ³΅μ‘λλ₯Ό κ³μ°ν΄λ³΄λ©΄ νμ€ν λ리긴 ν©λλ€.
C μ½λ
#include <stdio.h>
#define MAX 100002
void insertion_sort(int tiparr[], int tip, int count);
int main(void) {
int N = 0;
scanf("%d", &N);
long long sum = 0;
int tiparr[MAX] = { 0 };
int count = 0;
for (int i = 0; i < N; i++)
{
int tip = 0;
scanf("%d", &tip);
insertion_sort(tiparr, tip, count);
count++;
}
for (int i = 0; i < N ; i++)
{
if (tiparr[i] - i <= 0)
{
break;
}
else if(tiparr[i] -i > 0)
{
sum += tiparr[i] - i;
}
}
printf("%lld", sum);
return 0;
}
void insertion_sort(int tiparr[], int tip, int count)
{
tiparr[count] = tip;
int j = count;
while (j>0&&tiparr[j-1] < tiparr[j])
{
int temp = tiparr[j - 1];
tiparr[j - 1] = tiparr[j];
tiparr[j] = temp;
j--;
}
}```
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/1758
βοΈ μμλ μκ°
20λΆ
β¨ μλ μ½λ
μν κΈ°κ°μ΄κΈ°λ νκ³ μλ‘μ΄ κ°λ μ 곡λΆνκΈ°μ μκ°μ΄ λλνμ§ μμμ μ΄λ°μ νλ 그리λλ₯Ό κ°μ Έμμ΅λλ΅
λ¬Έμ μμ κ°νΈκ° λ°λ νμ μ΅λκ°μ ꡬν΄μΌν©λλ€.
μλλ€μ΄ κ°νΈμκ² μ£Όλ νμ μλ μ£Όλ €λ ν - (컀νΌλ₯Ό λ°μ μμ - 1) μ λλ€.
μ μμ ν΅ν΄ κ³μ°λ κ°μ΄ μμλΌλ©΄ μλλ€μ νμ μ£Όμ§ μμ΅λλ€.
μ 체 μλμ μμ μλ μλλ€μ΄ μ£Όλ €λ νμ μ²μμ μ£Όμ΄μ§κ³ λ°λμ§ μμ΅λλ€. κ·ΈλΌ νμ μ΅λκ°μ ꡬνκΈ° μν ν΅μ¬μ
μλ μ£Όλ €λ ν - (컀νΌλ₯Ό λ°μ μμ - 1) < 0 μ΄ λΆλΆμ λλ€. μλ μ£Όλ €λ νμ΄ ν° μλμ΄ κ³μν΄μ κΈ°λ€λ¦¬λ€ κ²°κ΅ νμ λͺ» μ£Όκ² λλ€λ©΄ μμ€μ΄ κ°μ₯ ν¬κ² λ©λλ€.
λ°λΌμ μλλ€μ΄ μλ μ£Όλ €λ νμ κΈ°μ€μΌλ‘ λ΄λ¦Όμ°¨μμΌλ‘ μ λ ¬νμ¬ μ€ μΈμ νμ ν©μ ꡬνλ©΄ μ΅λκ°μ΄ λ©λλ€.?.λ΅
μλμ½λ